package com.ocom.ugcapi.mq.consumer;

import com.google.gson.Gson;
import com.ocom.common.vo.pay.CallBackVo;
import com.ocom.ugcapi.client.PayHandleClientService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

/**
 * @Description: TODO
 * @Author: 朱晖
 * @Date: 2022年7月12日09:02:39
 **/
@Slf4j
@Component
public class SignConsumer {


	@Autowired
	private PayHandleClientService payHandleClientService;

	/**
	 * 请留意此处 监听的队列名称
	 */
	@RabbitHandler
	@RabbitListener(queues = "dead-sign-queue")
	public void listenLimitingQueue(Message message, @Headers Map<String, Object> headers,  Channel channel) throws IOException {

		try {
		//	System.out.println("sign 限流队列接收到消息:" + message);

			Gson gson=new Gson();
			String se = new String(message.getBody(), "UTF-8");
			CallBackVo callBackVo= gson.fromJson(se,CallBackVo.class);

			payHandleClientService.callback(callBackVo);
		}catch (Exception e){
			log.info("公众号充值-处理回调异常 【{}】" ,e);
		}

		//确认接收消息
		channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
	}
}
